<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class RSSItem {
	var $link;
	var $title;
	var $pubdate;
	var $description;
	
	function RSSItem() {
		
	}
	
	function setLink($link) {
		$this->link = $link;
	}
	
	function getLink() {
		return $this->link;
	}
	
	function setTitle($title) {
		$this->title = $title;
	}
	
	function getTitle() {
		return $this->title;
	}
	
	function setPubdate($pubdate) {
		$this->pubdate = $pubdate;
	}
	
	function getPubdate() {
		return $this->pubdate;
	}
	
	function setDescription($description) {
		$this->description = $description;
	}
	
	function getDescription() {
		return $this->description;
	}
	
	function toString() {
		$content = '';
		
		$content .= '		<item>' . "\n";
		$content .= '			<link><![CDATA[' . $this->link . ']]></link>' . "\n";
		$content .= '			<title><![CDATA[' . $this->title . ']]></title>' . "\n";
		$content .= '			<pubdate><![CDATA[' . $this->pubdate . ']]></pubdate>' . "\n";
		$content .= '			<description><![CDATA[' . $this->description . ']]></description>' . "\n";
		$content .= '		</item>' . "\n";
		
		return $content;
	}
}

class RSSAttribute {
	var $title;
	var $link;
	var $description;
	var $language;
	var $copyright;
	
	//constructor
	function RSSAttribute() {
		
	}
	
	//setter/getter
	function setTitle($title) {
		$this->title = $title;
	}
	
	function getTitle() {
		return $this->title;
	}
	
	function setLink($link) {
		$this->link = $link;
	}
	
	function getLink() {
		return $this->link;
	}
	
	function setDescription($description) {
		$this->description = $description;
	}
	
	function getDescription() {
		return $this->description;
	}
	
	function setLanguage($language) {
		$this->language = $language;
	}
	
	function getLanguage() {
		return $this->language;
	}
	
	function setCopyright($copyright) {
		$this->copyright = $copyright;
	}
	
	function getCopyright($copyright) {
		return $this->copyright;
	}
	
	//
	function toString() {
		$content = '';
		
		$content .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
		$content .= '<rss version="2.0">' . "\n";
		$content .= '	<channel>' . "\n";
		$content .= '		<title>' . $this->title . '</title>' . "\n";
		$content .= '		<link>' . $this->link . '</link>' . "\n";
		$content .= '		<description><![CDATA[' . $this->description . ']]></description>' . "\n";
		$content .= '		<language>' . $this->language . '</language>' . "\n";
		$content .= '		<copyright>' . $this->copyright . '</copyright>' . "\n";

		return $content;
	}
}

class RSSBase extends Base {
	var $owner;
	
	var $title;
	var $link;
	var $description;
	var $language;
	var $copyright;
	
	var $items;
	
	//constructor
	function RSSBase() {
		
	}
	
	function addItem($item) {
		if( $this->_not_null($item->link) && $this->_not_null($item->title) ) {
			$this->items[] = $item;
		}
	}
	
	function output() {
		return $this->_output();
	}
	
	//setter/getter
	function setTitle($title) {
		$this->title = $title;
	}
	
	function getTitle() {
		return $this->title;
	}
	
	function setLink($link) {
		$this->link = $link;
	}
	
	function getLink() {
		return $this->link;
	}
	
	function setDescription($description) {
		$this->description = $description;
	}
	
	function getDescription() {
		return $this->description;
	}
	
	function setLanguage($language) {
		$this->language = $language;
	}
	
	function getLanguage() {
		return $this->language;
	}
	
	function setCopyright($copyright) {
		$this->copyright = $copyright;
	}
	
	function getCopyright($copyright) {
		return $this->copyright;
	}
	
	//private
	function _generate_header() {
		$content = '';
		
		$content .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
		$content .= '<rss version="2.0">' . "\n";
		$content .= '	<channel>' . "\n";
		$content .= '		<title>' . $this->title . '</title>' . "\n";
		$content .= '		<link>' . $this->link . '</link>' . "\n";
		$content .= '		<description><![CDATA[' . $this->description . ']]></description>' . "\n";
		$content .= '		<language>' . $this->language . '</language>' . "\n";
		$content .= '		<copyright>' . $this->copyright . '</copyright>' . "\n";

		return $content;
	}
	
	function _generate_footer() {
		$content = '';
		
		$content .= '	</channel>' . "\n";
		$content .= '</rss>' . "\n";
		
		return $content;
	}
	
	function _genereate_items() {
		$content = '';
		
		if( is_array($this->items) ) {
			foreach($this->items as $item) {
				$content .= $item->toString();
			}
		}
		
		return $content;
	}
	
	function _output() {
		$content = '';
		
		$content .= $this->_generate_header();
		$content .= $this->_genereate_items();
		$content .= $this->_generate_footer();
		
		return $content;
	}
}

class RSSBaseD {
	var $attribute;
	var $items;
	
	//constructor
	function RSSBaseD() {
		
	}
	
	function setAttribute($attribute) {
		$this->attribute = $attribute;
	}
	
	function addItem() {
		if( $this->_not_null($item->link) && $this->_not_null($item->title) ) {
			$this->items[] = $item;
		}
	}
	
	function output() {
		return $this->_output();
	}
	
	//
	function _generate_header() {
		$content = '';
		
		$content .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
		$content .= '<rss version="2.0">' . "\n";
		$content .= '	<channel>' . "\n";
		//$content .= '		<title>' . $this->attribute->title . '</title>' . "\n";
		//$content .= '		<link>' . $this->attribute->link . '</link>' . "\n";
		//$content .= '		<description><![CDATA[' . $this->attribute->description . ']]></description>' . "\n";
		//$content .= '		<language>' . $this->attribute->language . '</language>' . "\n";
		//$content .= '		<copyright>' . $this->attribute->copyright . '</copyright>' . "\n";
		$content .= $this->attribute->toString();

		return $content;
	}
	
	function _generate_footer() {
		$content = '';
		
		$content .= '	</channel>' . "\n";
		$content .= '</rss>' . "\n";
		
		return $content;
	}
	
	function _genereate_items() {
		$content = '';
		
		if( is_array($this->items) ) {
			foreach($this->items as $item) {
				$content .= $item->toString();
			}
		}
		
		return $content;
	}
	
	function _output() {
		$content = '';
		
		$content .= $this->_generate_header();
		$content .= $this->_genereate_items();
		$content .= $this->_generate_footer();
		
		return $content;
	}
}
//
?>